package com.aegean.MonitorExamSYS.monitor.action;

import java.io.InputStream;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.aegean.MonitorExamSYS.monitor.business.MonitorBusiness;
import com.aegean.MonitorExamSYS.monitor.component.MonitorValue;
import com.opensymphony.xwork2.ActionSupport;

@Controller("NavigationMonitorArrangeForm")
@Scope("prototype")
public class NavigationMonitorArrangeForm extends ActionSupport implements
		ServletRequestAware {
	private static final long serialVersionUID = -4050851838527147772L;
	@Resource
	MonitorBusiness business;
	private int exam_Id;
	private int pq_Id;// 考场资格Id
	private String startTime;
	private String endTime;
	private String exam_Name;
	private String position_Name;
	private int person_Count;
	private String identity;
	private String position_Identity;
	private List<MonitorValue> monitors;
	private HttpServletRequest request;
	private HttpSession session;
	public String getPosition_Identity() {
		return position_Identity;
	}

	public void setPosition_Identity(String position_Identity) {
		this.position_Identity = position_Identity;
	}

	public String getIdentity() {
		return identity;
	}

	public void setIdentity(String identity) {
		this.identity = identity;
	}

	public int getExam_Id() {
		return exam_Id;
	}

	public void setExam_Id(int exam_Id) {
		this.exam_Id = exam_Id;
	}


	public int getPq_Id() {
		return pq_Id;
	}

	public void setPq_Id(int pq_Id) {
		this.pq_Id = pq_Id;
	}

	public String getStartTime() {
		return startTime;
	}

	public void setStartTime(String startTime) {
		this.startTime = startTime;
	}

	public String getEndTime() {
		return endTime;
	}

	public void setEndTime(String endTime) {
		this.endTime = endTime;
	}

	public String getExam_Name() {
		return exam_Name;
	}

	public void setExam_Name(String exam_Name) {
		this.exam_Name = exam_Name;
	}

	public String getPosition_Name() {
		return position_Name;
	}

	public void setPosition_Name(String position_Name) {
		this.position_Name = position_Name;
	}

	public int getPerson_Count() {
		return person_Count;
	}

	public void setPerson_Count(int person_Count) {
		this.person_Count = person_Count;
	}

	public List<MonitorValue> getMonitors() {
		return monitors;
	}

	public void setMonitors(List<MonitorValue> monitors) {
		this.monitors = monitors;
	}

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		person_Count = business.countOfExaminees(pq_Id);
		monitors = business.showMonitorValues(pq_Id);
		return SUCCESS;
	}

	public String downLoadExcel() throws Exception {
		return SUCCESS;
	}

	public InputStream getDownload() {
		try {
			com.aegean.MonitorExaxSYS.model.MonitorValue one = (com.aegean.MonitorExaxSYS.model.MonitorValue) session
					.getAttribute("MonitorLogin");
			monitors = business.showMonitorValues(pq_Id);
			return business.downExelForMonitor(exam_Name, position_Name,
					identity, startTime, endTime, person_Count,
					position_Identity, monitors, one.getUser_RealName());
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}
	}

	@Override
	public void setServletRequest(HttpServletRequest arg0) {
		// TODO Auto-generated method stub
		this.request = arg0;
		this.session = this.request.getSession();
	}

}
